<template>
  <div class="goods-list">
    <router-link :to="'/home/goodsinfo/'+ item.id" class="goods-item" v-for="item in goods" :key="item.id">
      <img :src="item.img_url" alt />
      <h1>{{ item.title }}</h1>
      <div class="info">
          <p class="price">
              <span class="now">&yen;{{ item.market_price }}</span>
              <span class="old">&yen;{{ item.sell_price }}</span>
          </p>
         <p class="sell">
          <span>热卖中</span>
          <span>剩{{ item.stock_quantity }}件</span>
        </p>
      </div>
    </router-link>

    <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      pageindex: 1,
      goods: []
    };
  },
  created() {
    this.getGoodsList();
  },
  methods: {
    getGoodsList() {
      this.$http.get("api/getgoods?pageindex="+ this.pageindex).then(result => {
        if (result.body.status === 0) {
          this.goods = this.goods.concat(result.body.message);
        }
      });
    },
    getMore(){
        this.pageindex++;
        this.getGoodsList();
    }
  }
};
</script>

<style lang="scss">
.goods-list {
    overflow: hidden;
    padding: 7px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
  .goods-item {
    float: left;
    padding: 2px;
    margin: 4px 0;
    box-shadow: 0 0 8px #ccc;
    width: 49%;
    min-height: 293px;
    border: 1px solid #ccc;
    img {
      width: 100%;
      min-height: 190px;
    }
    h1 {
        font-size: 14px;
        min-height: 40px;
    }
    .info {
        background-color: #eee;
        .price {
            margin: 0;
            padding: 5px;
            .now {
                color: red;
                font-weight: bold;
                font-size: 16px;
            }
            .old {
                font-size: 12px;
                margin-left: 10px;
                text-decoration: line-through;
            }
        }
        .sell {
            font-size: 13px;
            display: flex;
            justify-content: space-between;
            margin: 0;
            padding: 5px;
        }
    }
  }
}
</style>